<template>
  <div>
      <el-form ref="form" :model="building" label-width="80px" size="mini">
          <el-form-item label="楼栋名称">
              <el-input v-model="building.buildingName" @blur="checkname"></el-input>
          </el-form-item>
          <el-form-item label="楼栋号">
              <el-input v-model="building.buildingNumber"></el-input>
          </el-form-item>
          <el-form-item label="面积">
              <el-input v-model="building.buildingArea"></el-input>
          </el-form-item>
          <el-form-item label="位置">
              <el-input v-model="building.buildingLocation"></el-input>
          </el-form-item>
          <el-form-item label="楼层">
              <el-input v-model="building.floorsNumber"></el-input>
          </el-form-item>
          <el-form-item label="建成年份">
              <el-col :span="11">
                  <el-date-picker type="date" placeholder="选择日期" value-format="yyyy-MM-dd" v-model="building.buildingYear" style="width: 100%;"></el-date-picker>
              </el-col>
          </el-form-item>
          <el-form-item size="large">
              <el-button type="primary" @click="onSubmit">立即创建</el-button>
              <el-button>取消</el-button>
          </el-form-item>
      </el-form>


  </div>

</template>
<script>
    export default {
        name: "ManageBuildingAddView",
    data() {
    return {
     building: {
         buildingName: '',
         buildingNumber: '',
         buildingArea: '',
         buildingLocation: '',
         floorsNumber: '',
         buildingYear: '',
}
};
},
    methods: {
    onSubmit() {
        if(!this.building.buildingName){this.$message.error("请输入楼栋名称");return false}
        else if(!this.building.buildingNumber){this.$message.error("请输入楼栋号"); return false}
        else if(!this.building.buildingArea){return false}
        else if(!this.building.buildingYear){return false}
        else if(!this.building.buildingLocation){return false}

        this.$axios.post("/manage/buildingsave",this.building).then(res =>{
            if(res.data.msg=="添加成功"){
                alert("添加成功");
                this.building = {}
                this.value = ""
                this.$router.push("/manage/building")
            }
        });
},
        checkname(){
        this.$axios.post("/manage/checkbuildingname",this.building).then(res =>{
            console.log(res.data)
            if(res.data.building!=null){
                this.$message.error("楼名重复")
            }
        })
        }
}
};
</script>